QuickTime 3 Reference

Previous | Chapter Top | Chapter Contents | Next

Defining Override Samples

Once you have defined a key frame sample for the sprite track, you can add any number of override samples to modify sprite properties.

Listing 10 shows the portion of the AddSpriteTrackToMovie function that adds override samples to the sprite track to make the sprites appear to spin and move. For each override sample, the function modifies the space ship sprite's image index and location. The function calls SetSpriteData to update the appropriate property atoms in the sprite atom container. Then, the function calls AddSpriteToSample to add the sprite atom container to the sample atom container. After all of the modifications have been made to the override sample, the function calls AddSpriteSampleToMedia to add the override sample to the media.

After adding all of the override samples to the media, AddSpriteTrackToMovie calls EndMediaEdits to indicate that it is done adding samples to the media. Then, AddSpriteTrackToMovie calls InsertMediaIntoTrack to insert the new media segment into the track.

Listing 10 Adding override samples

// global constants
#define kNumOverrideSamples 199
#define kFirstSpaceShipImageIndex 4
#define kNumSpaceShipImages 24
#define kLastSpaceShipImageIndex (kFirstSpaceShipImageIndex +
    kNumSpaceShipImages - 1)
#define kSpriteMediaFrameDuration 8


imageIndex = kFirstSpaceShipImageIndex;
location.h = 0;
location.v = 80;
// for each override sample
for ( i = 1; i < kNumOverrideSamples; i++ )
{
    // clear out the sample and spriteData atom containers
    QTRemoveChildren (sample, 0);
    QTRemoveChildren (spriteData, 0);

    // bump the space ship's image index every third frame to spin
    if ( (i % 3) == 0 ) {
    
        imageIndex++;
        if (imageIndex > kLastSpaceShipImageIndex)
            imageIndex = kFirstSpaceShipImageIndex;
    }

    // bump location of space ship sprite in each frame by one pixel
    // vertically and two horizontally
    location.h += 2;
    location.v++;

    // add the space ship sprite to the override sample
    SetSpriteData (spriteData, &location, nil, nil, &imageIndex);
    err = AddSpriteToSample (sample, spriteData, 2);

    // ...
    // make modifications to other sprites and add to the override sample
    // ...

    // add the override sample to the media
    err = AddSpriteSampleToMedia (newMedia, sample,
        kSpriteMediaFrameDuration, false);
}

EndMediaEdits (newMedia);
InsertMediaIntoTrack (newTrack, 0, 0, GetMediaDuration (newMedia),
    0x010000);

© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next